$(document).ready(function(){		
    $("#query").autocomplete({
        source: function( request, response ) {
		
            var parametros = {
                "id_cat" : $('[name="id"]').val(),
                "term" : request.term
            };		
            $.ajax({        
                data:  parametros,	
                url: 'functions/searchAutocomplete.php',
                type:  'post',                            
                dataType: "json",
                success: function( data ) {
                    response( $.map( data, function( item ) {							
                        valor = item.title; 
                        return {
                            label: valor,
                            value: valor,
                            id: item.id
                        };
                    }));
                }
            });
        },
        minLength: 3,
        autoFocus: true
    });
	
		var tabNumber=0;
	$(".tab-item").each(function () {
              $(this).attr("id","tab-"+tabNumber);
              tabNumber++;
     })
    tabNumber=0;
	$(".item-box").each(function () {
              $(this).addClass("tab-"+tabNumber);
              tabNumber++;
     })
	 $(".tab-item").click(function(){
		if (!($(this).hasClass('selected-tab'))){
			$(".selected-tab").removeClass("selected-tab");
			$(this).addClass("selected-tab");			
			var prevBox = $(".selected-box");
			$("."+$(this).attr("id")).addClass("selected-box");
			prevBox.removeClass("selected-box");
			if ($(this).attr('id') == 'tab-1'){
				$('#zoom01, .cloud-zoom-gallery').CloudZoom();
				/*$("#littleOnes td a").first().click();*/
				/*CloudZoom.quickStart();*/
			}
		}
	});
	
	$("#viewGallery").click(function(){
		$("#tab-1").click();
	});
	$(".description").click(function(){
		$("#tab-0").click();
	});
	if($("#seller_id").length>0){
		var id_vendedor = $("#seller_id").val();
		viewActiveAuctions(id_vendedor);
		$("#viewActiveAuctions").popover({placement:'top', trigger:'hover'});
	}	
	
	$('#zoom01, .cloud-zoom-gallery').CloudZoom();
	/*CloudZoom.quickStart();*/
	
	$(".range").click(function(){
		$(".selectedRange").removeClass("selectedRange");
		$(this).addClass("selectedRange");			
	});
	
});

function viewActiveAuctions(id){
	var parametros = {
		"id_seller" : id
	};		
	$.ajax({        
		data:  parametros,	
		url: 'functions/viewActiveAuctions.php',
		type:  'post',                            
		dataType: "text",	
		success: function( data ) {					
			$("#viewActiveAuctions").attr("data-content", data);
		}
	});

}

 function checkMaxAuction(idItem){
       var parametros = {
               "idItem" : idItem,
			   "bid" : $('#bidOfferted').val()
       };                
       $.ajax({        
               data:  parametros,        
               url: 'functions/checkMaxAuction.php',
               type:  'post',                            
               dataType: "text",        
               success: function( data ) {
                       if(data == 'false'){
							var lowerbidMSG = $("#lower_bid").val();
							alert(lowerbidMSG);
                       }else{
					   		$("#formBid").submit();
					   }					   
               }        
       });

}
